@extends('admin.layouts')
@section('style')
    <style>
        html,body{
            height:100%;
        }
    </style>
@endsection
@section('main')

    <form class="layui-form luck-pane" method="post">
        <div class="luck-content clearfix">
            <div class="layer-box">
                <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                    <ul class="layui-tab-title">
                        <li class="layui-this">{{trans('config.basic')}}</li>
                        <li>{{trans('config.seo_set')}}</li>
                    </ul>
                    <div class="layui-tab-content layui-form-pane">
                        <div class="layui-tab-item layui-show">
                            {{csrf_field()}}
                            <input type="hidden" name="id" value="{{$data->id}}">
                            <div class="layui-form-item">
                                <label class="luck-form-label">{{trans('config.column')}}</label>
                                <div class="layui-input-inline">
                                    <select name="pid" lay-verify="required">
                                        <option value="0">{{trans('config.astop')}}</option>
                                        @foreach($cates as $v)
                                            <option value="{{$v->id}}" @if($data->pid==$v->id) selected="selected" @endif @if(in_array($v->id,$ids)) disabled="disabled" @endif>{{$v->_cate_name}}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="luck-form-label">{{trans('config.category')}}{{trans('config.name')}}</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="name" lay-verify="new_required" class="layui-input" value="{{$data->name}}">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="luck-form-label">{{trans('config.englishname')}}</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="catdir" class="layui-input" value="{{$data->catdir}}">
                                </div>
                            </div>
                            <div class="layui-form-item" id="img" @if(!$data->image)style="display: none;"@endif>
                                <label class="luck-form-label"></label>
                                <div class="layui-input-inline">
                                    <img src="/{{$data->image}}" style="max-width:100%;max-height:150px;" />
                                    <input type="text" name="image" value="{{$data->image}}" class="layui-input" style="display: none;">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="luck-form-label">{{trans('config.category')}}{{trans('config.image')}}</label>
                                <div class="layui-input-inline">
                                    <input type="file" name="file" class="layui-upload-file" lay-title="{{trans('config.add')}}{{trans('config.category')}}{{trans('config.image')}}" value="{{$data->image}}">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="luck-form-label">{{trans('config.category')}}{{trans('config.type')}}</label>
                                <div class="layui-input-inline" id="type">
                                    <input type="radio" name="type" value="0" title="{{trans('config.category')}}" @if($data->type==0)checked="checked"@endif>
                                    <input type="radio" name="type" value="1" title="{{trans('config.single')}}{{trans('config.page')}}" @if($data->type==1)checked="checked"@endif>
                                    <input type="radio" name="type" value="2" title="{{trans('config.links')}}" @if($data->type==2)checked="checked"@endif>
                                </div>
                            </div>
                            <div class="layui-form-item" @if($data->type!=2)style="display: none;"@endif id="links">
                                <label class="luck-form-label">{{trans('config.links')}}</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="links" lay-verify="new_url" class="layui-input" value="{{$data->links}}">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="luck-form-label">{{trans('config.as')}}{{trans('config.menu')}}</label>
                                <div class="layui-input-inline">
                                    <input type="radio" name="showed" value="1" title="{{trans('config.yes')}}" @if($data->showed==1)checked="checked"@endif>
                                    <input type="radio" name="showed" value="0" title="{{trans('config.no')}}" @if($data->showed==0)checked="checked"@endif>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="luck-form-label">{{trans('config.template')}}</label>
                                <div class="layui-input-inline luck-select">
                                    <select name="template">
                                        <option value="">{{trans('config.default')}}</option>
                                        @foreach($template as $v)
                                            <option value="{{$v}}" @if($data->template==$v)selected="selected"@endif>{{$v}}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-tab-item">
                            <div class="layui-form-item">
                                <label class="luck-form-label">META Title</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="seo_title" class="layui-input" value="{{$data->seo_title}}">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="luck-form-label">META Keywords</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="seo_keyword" class="layui-input" value="{{$data->seo_keyword}}">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="luck-form-label">META Description</label>
                                <div class="layui-input-inline">
                                    <textarea name="seo_description" class="layui-textarea">{{$data->seo_description}}</textarea>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="luck-footer luck-footer-right luck-footer-padding">
            <div class="luck-block">
                <button class="layui-btn" lay-submit lay-filter="sub">{{trans('config.btn_submit')}}</button>
            </div>
        </div>
    </form>

@endsection

@section('script')

    <script>
        layui.use(['jquery','simpleform','layer','upload'],function(){
            var $= layui.jquery;
            var index = parent.layer.getFrameIndex(window.name);
            var form = layui.form();
            var load;
            layui.upload({
                url: '{{url("admin/upload")}}?type=category&_token={{csrf_token()}}' //上传接口
                ,before: function(){
                    load=layer.load(1, {
                        shade: [0.1,'#fff']
                    });
                },success: function(res){ //上传成功后的回调
                    if(res.status==200){
                        $("#img").show().find('img').attr('src','/'+res.data.src);
                        $("input[name=image]").val(res.data.src);
                        layer.msg(res.msg,{icon:1,shift:5});
                    }else{
                        layer.msg(res.msg,{icon: 5,shift:6});
                    }
                    layer.close(load);
                }
            });
            $('#type>div').click(function(){
                if($(this).prev().val()==2){
                    $("#links").show();
                }else{
                    $("#links").hide();
                }
            });

            form.verify({
                new_url:function(value){
                    if(!/(^#)|(^http(s*):\/\/[^\s]+\.[^\s]+)/.test(value) && !this.new_required(value)){
                        return "{{ trans('config.vali_url') }}";
                    }
                },
                new_required:function(value){
                    if(!/[\S]+/.test(value)){
                        return "{{ trans('config.vali_required') }}";
                    }
                }
            });

            form.on('submit(sub)', function(data){
                $.ajax({
                    url:"{{url('admin/categoryedit')}}",
                    type:"post",
                    data:data.field,
                    beforeSend:function(){
                        load=layer.load(1, {
                            shade: [0.1,'#fff']
                        });
                    },
                    success:function(data){
                        if(data.status==200){
                            layer.msg(data.msg,{icon:1,shift:5});
                            parent.layer.close(index);
                            if(data.url=="reload"){
                                parent.location.reload();
                            }
                        }else{
                            layer.msg(data.msg,{icon: 5,shift:6});
                        }
                    },
                    complete:function(){
                        layer.close(load);
                    },
                    error:function(){
                        layer.msg("{{trans('config.connect')}}",{icon: 5,shift:6});
                    }
                })
                return false;
            });
        });
    </script>
@endsection